
url=require("url")

let downImgUtils=require(staticPath+"tools/downImgUtils.js")
let yuqueUtils=require(staticPath+"tools/yuqueUtils.js")



app.get('/tools/downImg', async function (req, res) {
    const { title } = url.parse(req.url, true).query;
    const imgUrl=  req.url.split("imgUrl=")[1];
    let response=await downImgUtils.downQrCodeImg(imgUrl);
    res.writeHeader(200,{'Context-Type':'image/png',"Content-Disposition":"attachment; filename="+encodeURI(title)})
    res.end(response.data)
})

/**
 * 获取语雀html模板
 */
app.get('/tools/getYuqueArtile', async function (req, res) {
    const { title } = url.parse(req.url, true).query;
    let data=await yuqueUtils.getYuqueArtile(title)
    let r= M.result(data)
    res.send(r)
})

/**
 * 获取语雀贺卡模板
 */
app.get('/tools/greetingCard', async function (req, res) {
    const { title } = url.parse(req.url, true).query;
    let data=await yuqueUtils.greetingCard(title)
    let r= M.result(data)
    res.send(r)
})


/**
 * 清除语雀缓存
 */
app.get('/tools/cleanYuqueCache', async function (req, res) {
    const { title } = url.parse(req.url, true).query;
    if(title){
        yuqueUtils.cacheData[title]=null;
    }else {
        yuqueUtils.cacheData={};
    }
    if(title){
        await yuqueUtils.getYuqueArtile(title)
    }
    let r= M.result()
    res.send(r)
})
